package com.help10000.rms.ui.adapter

import android.content.Context
import android.content.Intent
import android.view.View
import android.view.ViewGroup
import com.amir.common.beans.MessageItem
import com.amir.common.holder.CommonViewHolder
import com.amir.common.mvp.base.BaseRecyclerViewAdapter
import com.help10000.rms.R
import com.help10000.rms.common.OrderType
import com.help10000.rms.ui.activitys.OrderActivity
import com.help10000.rms.ui.utils.PageUtils

class MessageListAdapter(
    context: Context?,
    dataList: List<MessageItem>
) :
    BaseRecyclerViewAdapter<MessageItem>(context, dataList) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommonViewHolder {
        var view = layoutInflater.inflate(R.layout.item_msg_item_detail, parent, false)
        return CommonViewHolder(view)
    }

    override fun onBindViewHolder(holder: CommonViewHolder, position: Int) {
        var messageItem = dataList[position]
        holder.setText(R.id.msgTitleTv, text = "${messageItem.MsgTitle}")
        holder.setText(R.id.msgDetailTv, text = "${messageItem.MsgContent}")
        holder.setText(R.id.msgTimeTv, text = "${messageItem.CreateDate}")
        holder.setViewVisibility(
            R.id.msgReadState,
            if (messageItem.IsRead == 1) View.GONE else View.VISIBLE
        )
        holder.setCommonClickListener(object : CommonViewHolder.onItemCommonClickListener {
            override fun onItemClickListener(position: Int) {
                when (messageItem.OpenUrl) {
                    "MY_ORDER_LIST" -> {
                        PageUtils.jumpToActivity(mContext, OrderActivity::class.java)
                    }
                    "MY_NEWORDER_LIST" -> {
                        var intent = Intent(mContext, OrderActivity::class.java)
                        intent.putExtra("type", OrderType.ROB_ORDER.ordinal)
                        mContext.startActivity(intent)
                    }
                }
            }

            override fun onItemLongClickListener(position: Int) {

            }
        })
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

}
